package day20240908;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Locale;

@WebServlet("/judgment")
public class JudgmentSystem extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String len = req.getParameter("len");
        String header = len;
        if (len == null) {
            header = req.getHeader("accept-language");
        }
        PrintWriter out = resp.getWriter();
        String l = "null";
        if (header.startsWith("zh")) {
            resp.setContentType("text/html");
            l = "当前浏览器的语言为 中文";
        }
        if (header.startsWith("en")) {
            l = "This is English";
        }

        out.write(l);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();
        System.out.println("JudgmentSystem.doPost");
        writer.write("JudgmentSystem.doPost");
    }

}
